<%@include file="conexao.jsp" %> 
<%@page import="java.sql.*" %>

<%  String usuariolog = (String)session.getAttribute("usuario");
	if(usuariolog != null){
%>
<%
    //JSP = java dentro do html
    //servlet = html dentro do java


    if(request.getParameter("ac").equals("adicionar")){
       
        try{
            String usuario = request.getParameter("usuario"); 
            String senha = request.getParameter("senha"); 
            String nivel = request.getParameter("nivel"); 
            String sql = "insert into tblusuario (usuario, senha, nivel) values('"+usuario+"','"+senha+"','"+nivel+"')";
            stm.execute(sql);
        }catch(SQLException e){
            e.printStackTrace();
        }
  
        stm.close();
        con.close();
    }
    
    if(request.getParameter("ac").equals("atualizar")){
        
        int id = Integer.parseInt(request.getParameter("id"));
        String usuario = request.getParameter("usuario"); 
        String senha = request.getParameter("senha"); 
        String nivel = request.getParameter("nivel");
        
        String sql = "update tblusuario set usuario='"+usuario+"', senha='"+senha+"', nivel='"+nivel+"' where id="+id+"";
        
        stm.execute(sql);
        stm.close();
        con.close();
    }
    
    if(request.getParameter("ac").equals("rm")){
        
        int id = Integer.parseInt(request.getParameter("id"));
                
        String sql = "delete from tblusuario where id="+id+"";
        
        stm.execute(sql);
        stm.close();
        con.close();
    }
    


%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Programa de Testes</title>
        <link  href="css/geral.css" rel="stylesheet" type="text/css" />
        <link rel="shortcut icon" href="favicon.ico" />
        
    </head>
    <body>
        <div id="tudo">
            
            <div id="cabecalho"></div>
            
            <div id="menu">
                <jsp:include page="menuprincipal.jsp"></jsp:include>
            </div>
            
            <div id="principal">
                <table border="0" align="center">
                    <thead>
                        <tr>
                            <td><h1>Cadastro Efetuado</h1></td>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </body>
</html>

<% }else{
	request.getRequestDispatcher("index.jsp").forward(request, response);
};%>

